import {
	request
} from '@/utils/request.js'

const BaseUrl = 'http://localhost:8080/api'
export const wxLogin = (res) => request({
	url: '/users/login',
	method: 'post',
	data: {
		code: res.code
	},
})

//登录
export const login = () => {
	wx.login({
		success: res => {
			// 发送code到后端服务进行处理
			uni.request({
				url: BaseUrl + '/users/login',
				method: 'POST',
				data: {
					code: res.code
				},
				success: res => {
					// 保存返回的openid和session_key到本地
					const userInfo = res.data.userInfo
					uni.setStorageSync('userInfo', userInfo)
					// uni.setStorageSync('unionid', unionid)
				}
			})
		}
	})
}

//绑定手机号
export const openidBindPhone = (data) => request({
	url: '/users/bindPhone',
	method: 'post',
	data
})

//查看手机绑定状态
export const reqGetPhoneStatus = (data) => request({
	url: "/users/getPhone",
	method: 'post',
	data: data
})

//签到
export const reqSignIn = (data) => request({
	url: '/users/sign',
	method: 'post',
	data
})
